{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "6e736ed0",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import glob\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "f9a6c7db",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Replace values for D column (from second row onwards)\n",
    "replacement_values = [\n",
    "    5852507880.333229, 1912138912041.068848, 192162603449.710999, \n",
    "    257351173124.112274, 776474415494.436279, 333459250881.328735, \n",
    "    311909174006.904968, 556580037226.484863, 15373047453.513386, \n",
    "    363267475370.696106\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "5cff827a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Path to the Excel files\n",
    "file_pattern = 'D:\\\\ABiomass\\\\GFAS\\\\2013\\\\201312\\\\fqtj\\\\GFAS201312_*.xls'\n",
    "output_data = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "6e58e3c6",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Iterate over each Excel file that matches the pattern\n",
    "for file_path in glob.glob(file_pattern):\n",
    "    # Read the Excel file\n",
    "    df = pd.read_excel(file_path)\n",
    "\n",
    "    # Calculate values for column N using the formula: I * replacement_values / 1000 * 60 * 60 * 24\n",
    "    df['N'] = df['MEAN'] * pd.Series(replacement_values) / 1000 * 60 * 60 * 24\n",
    "\n",
    "    # Append column N to output data\n",
    "    output_data.append(df['N'].values)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "ce7ff9bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create a DataFrame for the output with each N column result as a separate column\n",
    "output_df = pd.DataFrame(output_data).T\n",
    "\n",
    "# Save the output to a new Excel file\n",
    "output_df.to_excel('D:\\\\ABiomass\\\\GFAS\\\\2013\\\\201312\\\\fqtj\\\\GFAS201312all.xlsx', index=False, header=[f\"GFAS2013test_{i+1}\" for i in range(1, 32)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "44686bb6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
